package qps;

import com.alibaba.fastjson.JSON;

/**
 * HTTP响应结果
 *
 * @author lip.li
 */
public class HttpResponseMsg<V> {

    private int status;

    private int errorCode;

    private V body;

    public HttpResponseMsg() {
    }

    public HttpResponseMsg(V body) {
        this.body = body;
    }

    public HttpResponseMsg(int status, V body) {
        this.status = status;
        this.body = body;
    }

    public HttpResponseMsg(int errorCode, int status, V body) {
        this.status = status;
        this.body = body;
        this.errorCode = errorCode;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public V getBody() {
        return body;
    }

    public void setBody(V body) {
        this.body = body;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String toJsonString() {
        return JSON.toJSONString(this);
    }

//    public V convertBody(Class<V> clazz) {
//        if (body == null) {
//
//            return null;
//        }
//        if (body instanceof JSONObject) {
//            return ((JSONObject) body).toJavaObject(clazz);
//        }
//        return clazz.cast(body);
//    }
}
